<?php
$params = require (__DIR__ . '/params.php');

$config = [
    'id' => 'basic',
    'basePath' => dirname(__DIR__),
    'bootstrap' => [
        'log'
    ],
    'language' => 'zh-CN',
    'defaultRoute' => '/',
    'components' => [
        'request' => [
            // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
            'cookieValidationKey' => 'IfFV6zvorPeU5A9xQTRMxKP2BNUNlfsd',
            'parsers' => [
                'application/json' => 'yii\web\JsonParser',
                'text/json' => 'yii\web\JsonParser',
            ],
        ],
        'cache' => [
            'class' => 'yii\caching\FileCache'
        ],
        'user' => [
            'identityClass' => 'app\modules\system\models\User',
            'enableAutoLogin' => true
        ],
        'errorHandler' => [
            'errorAction' => '/error/error'
        ],
        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => [
                        'error',
                        'warning'
                    ]
                ]
            ]
        ],
        'db' => require (__DIR__ . '/db.php'),
        'authManager' => [
            'class' => 'yii\rbac\DbManager',
            'itemTable' => 'auth_item',
            'assignmentTable' => 'auth_assignment',
            'itemChildTable' => 'auth_item_child',
            'ruleTable' => 'auth_rule'
        ],
        'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            // 'suffix'=>'.html',
            'rules' => [
                "<controller:\w+>/<id:\d+>" => "<controller>/index",
                "<module:\w+>/<controller:\w+>/<id:\d+>" => "<module>/<controller>/view",
                "<module:\w+>/<controller:\w+>/<action:\w+>" => "<module>/<controller>/<action>"
            ]
        ],
        'miniprogram'=>[
            'class'=>'app\components\MiniProgram',
            'config'=>$params['miniprogram']
        ],
        'cache'=>[
                'class' => 'yii\redis\Connection',
                'hostname' => '127.0.0.1',
                'port' => 6379,
                'database' => 0,
        ],
    ]
    ,
    'params' => $params,
    'modules' => require (__DIR__ . '/modules.php')
];

if (YII_ENV_DEV) {
    // configuration adjustments for 'dev' environment
    $config['bootstrap'][] = 'debug';
    $config['modules']['debug'] = [
        'class' => 'yii\debug\Module',
        'allowedIPs' => [
            '127.0.0.1',
            '192.168.99.*',
            '59.108.15.176'
        ]
    ];
    
    $config['bootstrap'][] = 'gii';
    $config['modules']['gii'] = [
        'class' => 'yii\gii\Module',
        'allowedIPs' => [
            '127.0.0.1',
            '192.168.99.*',
            '59.108.15.176'
        ]
    ];
}

return $config;
